package com.springboot.ball.service.impl.user.account;

import com.springboot.ball.mapper.UserMapper;
import com.springboot.ball.pojo.User;
import com.springboot.ball.service.user.account.UpdateUserPhotoService;
import com.springboot.ball.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@Slf4j
public class UpdateUserPhotoServiceImpl implements UpdateUserPhotoService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public Result updateUserPhoto(Integer userId, String photoUrl) {
        User user = userMapper.selectById(userId);
        if (user == null) {
            return Result.error("用户不存在");
        }
        user.setPhoto(photoUrl);
        user.setUpdatetime(LocalDateTime.now());
        userMapper.updateById(user);
        log.info("用户{}头像已更新", user.getUsername());
        return Result.success(photoUrl);
    }
}
